package com.songxh.core.handler;

import com.songxh.core.base.CommonResult;
import com.songxh.core.exception.BizException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 *
 * @author songxh
 * @create 2023-01-29-17:14
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    private final Logger log = LoggerFactory.getLogger(this.getClass());

    /**
     * 对自定义异常BizException进行处理
     * @param exception
     * @return
     */
    @ExceptionHandler(value = BizException.class)
    public CommonResult bizExceptionHandler(BizException exception) {
        exception.printStackTrace();
        log.info("业务异常：{}", exception.getMessage());
        return CommonResult.failure(500, exception.getMessage());
    }
}
